
package net.atremmedia.gwt.actionjava.examples.basics.samples;

import net.atremmedia.gwt.actionjava.examples.AJExample;
import net.atremmedia.gwt.actionjava.examples.frame.AJExampleOverview;
import actionjava.display.Graphics;
import actionjava.display.Shape;
import actionjava.display.Sprite;
import actionjava.geom.Color;
import com.allen_sauer.gwt.log.client.Log;

public class Distance extends AJExample
{
	public static final String NAME = "Distance";
	public static final String DESCRIPTION = "Description";
	public static final String EXAMPLE_SRC = "https://code.google.com/p/gwt-actionjava/source/browse/trunk/aj-examples/aj-examples-basics/src/main/java/net/atremmedia/gwt/actionjava/examples/basics/samples/Distance.java";

	private Shape ball;
	private double angle = 0;
	private double centerScale = 1;
	private double range = .5;
	private double speed = .1;

	public Distance(AJExampleOverview base)
	{
		super(NAME, DESCRIPTION, EXAMPLE_SRC, base);
	}

	@Override
	public void run()
	{
		Sprite sprite1 = new Sprite();
		Graphics graphs = sprite1.getGraphics();
		graphs.beginFill(Color.RED.getHexValue());
		graphs.drawRect(-5, -5, 10, 10);
		graphs.endFill();
		sprite1.setX(Math.random() * getWidth());
		sprite1.setY(Math.random() * getHeight());

		addChild(sprite1);

		Sprite sprite2 = new Sprite();
		graphs = sprite2.getGraphics();
		graphs.beginFill(Color.BLUE.getHexValue());
		graphs.drawRect(-5, -5, 10, 10);
		graphs.endFill();
		sprite2.setX(Math.random() * getWidth());
		sprite2.setY(Math.random() * getHeight());

		addChild(sprite2);

		double dx = sprite1.getX() - sprite2.getX();
		double dy = sprite1.getY() - sprite2.getY();
		double dist = Math.round(Math.sqrt(dx * dx + dy * dy));

		Log.fatal("Distance: " + dist);
	}
}
